- page_title "用户"
= render 'shared/show_aside'

.admin-filter
  %ul.nav-links
    %li{class: "#{'active' unless params[:filter]}"}
      = link_to admin_users_path do
        当前
        %small.badge= number_with_delimiter(User.active.count)
    %li{class: "#{'active' if params[:filter] == "admins"}"}
      = link_to admin_users_path(filter: "admins") do
        管理
        %small.badge= number_with_delimiter(User.admins.count)
    %li.filter-two-factor-enabled{class: "#{'active' if params[:filter] == 'two_factor_enabled'}"}
      = link_to admin_users_path(filter: 'two_factor_enabled') do
        两步验证启用
        %small.badge= number_with_delimiter(User.with_two_factor.count)
    %li.filter-two-factor-disabled{class: "#{'active' if params[:filter] == 'two_factor_disabled'}"}
      = link_to admin_users_path(filter: 'two_factor_disabled') do
        两步验证禁用
        %small.badge= number_with_delimiter(User.without_two_factor.count)
    %li.filter-external{class: "#{'active' if params[:filter] == 'external'}"}
      = link_to admin_users_path(filter: 'external') do
        外部的
        %small.badge= number_with_delimiter(User.external.count)
    %li{class: "#{'active' if params[:filter] == "blocked"}"}
      = link_to admin_users_path(filter: "blocked") do
        禁用的
        %small.badge= number_with_delimiter(User.blocked.count)
    %li{class: "#{'active' if params[:filter] == "wop"}"}
      = link_to admin_users_path(filter: "wop") do
        无项目
        %small.badge= number_with_delimiter(User.without_projects.count)

  .row-content-block.second-block
    .pull-right
      .dropdown.inline
        %a.dropdown-toggle.btn{href: '#', "data-toggle" => "dropdown"}
          %span.light
          - if @sort.present?
            = sort_options_hash[@sort]
          - else
            = sort_title_name
          %b.caret
        %ul.dropdown-menu
          %li
            = link_to admin_users_path(sort: sort_value_name, filter: params[:filter]) do
              = sort_title_name
            = link_to admin_users_path(sort: sort_value_recently_signin, filter: params[:filter]) do
              = sort_title_recently_signin
            = link_to admin_users_path(sort: sort_value_oldest_signin, filter: params[:filter]) do
              = sort_title_oldest_signin
            = link_to admin_users_path(sort: sort_value_recently_created, filter: params[:filter]) do
              = sort_title_recently_created
            = link_to admin_users_path(sort: sort_value_oldest_created, filter: params[:filter]) do
              = sort_title_oldest_created
            = link_to admin_users_path(sort: sort_value_recently_updated, filter: params[:filter]) do
              = sort_title_recently_updated
            = link_to admin_users_path(sort: sort_value_oldest_updated, filter: params[:filter]) do
              = sort_title_oldest_updated

      = link_to '新用户', new_admin_user_path, class: "btn btn-new"
    = form_tag admin_users_path, method: :get, class: 'form-inline' do
      .form-group
        = search_field_tag :name, params[:name], placeholder: '姓名、邮箱或用户名', class: 'form-control', spellcheck: false
        = hidden_field_tag "filter", params[:filter]
      = button_tag class: 'btn btn-primary' do
        %i.fa.fa-search


.panel.panel-default
  %ul.well-list
    - @users.each do |user|
      %li
        .list-item-name
          - if user.blocked?
            = icon("lock", class: "cred")
          - else
            = icon("user", class: "cgreen")
          = link_to user.name, [:admin, user]
          - if user.admin?
            %strong.cred (管理)
          - if user.external?
            %strong.cred (外部)
          - if user == current_user
            %span.cred 自己
        .pull-right
          %span.light
            %i.fa.fa-envelope
            = mail_to user.email, user.email, class: 'light'
          &nbsp;
          .pull-right
            = link_to '编辑', edit_admin_user_path(user), id: "edit_#{dom_id(user)}", class: 'btn-grouped btn btn-xs'
            - unless user == current_user
              - if user.ldap_blocked?
                = link_to '#', title: '无法启用 LDAP 禁用用户', data: {toggle: 'tooltip'}, class: 'btn-grouped btn btn-xs btn-success disabled' do
                  %i.fa.fa-lock
                  启用
              - elsif user.blocked?
                = link_to '启用', unblock_admin_user_path(user), method: :put, class: 'btn-grouped btn btn-xs btn-success'
              - else
                = link_to '禁用', block_admin_user_path(user), data: {confirm: '用户将被禁用！确定要继续么？'}, method: :put, class: 'btn-grouped btn btn-xs btn-warning'
              - if user.access_locked?
                = link_to '解锁', unlock_admin_user_path(user), method: :put, class: 'btn-grouped btn btn-xs btn-success', data: { confirm: '确定要继续么？' }
              - if user.can_be_removed?
                = link_to '销毁', [:admin, user], data: { confirm: "用户 #{user.name} 将被删除！所有该用户的相关内容也会被删除！要不要只禁用用户？确定要继续么？" }, method: :delete, class: 'btn-grouped btn btn-xs btn-remove'
= paginate @users, theme: "gitlab"
